<template>
  <div class="login-header">
    <van-nav-bar
      :title="title"
      :right-text="loginRgister"
      left-arrow
      @click-left="onClickLeft"
      @click-right="onClickRight"
    />
  </div>
</template>

<script>
export default {
  data() {
    return {
      title: "登录",
      loginRgister: "注册",
      showLoginRgister: true
    };
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    onClickRight() {
      if (this.showLoginRgister) {
        this.title = "注册";
        this.loginRgister = "登录";
        this.showLoginRgister = !this.showLoginRgister;
        this.$router.push("/user/register");
      } else {
        this.title = "登录";
        this.loginRgister = "注册";
        this.showLoginRgister = !this.showLoginRgister;
        this.$router.push("/user/login");
      }
      this.$emit("showLoginRgister", this.showLoginRgister);
    }
  }
};
</script>

<style lang="stylus" scoped>
.login-header {
  height: 1.173rem;
  line-height: 1.173rem;
  font-size: 0.48rem;

  .back {
    margin-left: 0.2rem;
  }

  .register {
    margin-right: 0.2rem;
  }
}
</style>
